package main

import (
	"fmt"
	"time"
)
//利用阻塞
func fibonacci(out chan<- int, quit chan struct{}) {

	x, y := 1, 1
	for {
		select {
		case out <- x:
			x, y = y, x+y
		case <-quit:
			return
		}
	}
}
func main() {
	quit := make(chan struct{})
	ch := make(chan int)

	go func() {

		//控制斐波那契数列次数
		for i := 0; i < 10; i++ {
			num := <-ch
			time.Sleep(time.Second * 2)
			fmt.Print(num, " ")
		}
		close(quit)
	}()
	fibonacci(ch, quit)
}
